﻿using STHPMS1.DAL.D_Core;
using System.Data;
using ServiceStack.OrmLite;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore.I_DAL.Repository;
using System.Collections.Generic;

namespace STHPMS1.DAL.D_Repository
{
    public class E_NetevaluRepository : DalBase, IE_NetevaluRepository
    {

        public double? GetLenght(string inspecid, string searchvalue)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select sum(B_UNIT.ENDMP-B_UNIT.BEGINMP) as Lenght  from E_ROADWAYDETAIL "
                                        + "left join B_UNIT on E_ROADWAYDETAIL.UNIT=B_UNIT.UNIT  "
                                        + "left join B_INVNTORY_UNIT on E_ROADWAYDETAIL.UNIT=B_INVNTORY_UNIT.UNIT "
                                        + "left join B_INVNTORY  on B_INVNTORY_UNIT.SEGID=B_INVNTORY.SEGID "
                                        + "where INSPECID='" + inspecid + "' " + searchvalue + "";
            return conn.Scalar<double?>(strsql);
        }


        public double? GetAvageMQI(string inspecid, string searchvalue)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select sum((B_UNIT.ENDMP-B_UNIT.BEGINMP)*MQI)/ SUM(B_UNIT.ENDMP-B_UNIT.BEGINMP) as Lenght  from E_ROADWAYDETAIL "
                                        + "left join B_UNIT on E_ROADWAYDETAIL.UNIT=B_UNIT.UNIT  "
                                        + "left join B_INVNTORY_UNIT on E_ROADWAYDETAIL.UNIT=B_INVNTORY_UNIT.UNIT "
                                        + "left join B_INVNTORY  on B_INVNTORY_UNIT.SEGID=B_INVNTORY.SEGID "
                                        + "where INSPECID='" + inspecid + "' " + searchvalue + "";
            return conn.Scalar<double?>(strsql);
        }
    }
}
